import { cjRequest as request } from '@/service'

interface ResultType {
  result: {
    resultCode: string
    resultMessage: string
  }
  data: object
}

/** 适配接口返回结果 */
function adapter(obj: ResultType) {
  if (obj.result.resultCode == '000000') {
    return obj.data
  }
  throw new Error(obj?.result?.resultMessage)
}

/** 获取字典项 */
export const queryZd = (params?: any) =>
  request.get(`/pc-zd-model/query/zd`, { params }).then((res) => adapter(res as any))

/** 获取职务信息 */
export const queryZwxx = (params?: any) =>
  request.get(`/pc-zd-model/query/zdByJgxz`, { params }).then((res) => adapter(res as any))

/** 机构登录 */
export const login = (data?: any) =>
  request.post(`/pc-login/login`, data).then((res) => adapter(res as any))

/** 查询消防救援机构树 */
export const queryFireControlTree = (params?: any) =>
  request.get(`/xfjg-jyjg-model/queryJcXfjgJyjgTree`, { params }).then((res) => adapter(res as any))

/** 查询救援人员信息 */
export const queryJyry = (params?: any) =>
  request.get(`/pc-xfjg-jyry-model/query/jyry`, { params }).then((res) => adapter(res as any))

/** 新增救援人员信息 */
export const addJyry = (data?: any) =>
  request.post(`/pc-xfjg-jyry-model/insert/jyry`, data).then((res) => adapter(res as any))

/** 删除救援人员信息 */
export const deleteJyry = (data?: any) =>
  request.post(`/pc-xfjg-jyry-model/delete/jyry`, data).then((res) => adapter(res as any))

/** 根据姓名查询全部救援人员信息 */
export const queryAllJyry = (params?: any) =>
  request.get(`/xfjg-jyry-model/query/jyry`, { params }).then((res) => adapter(res as any))

/** 设置救援机构性质 */
export const addJyjgxz = (data?: any) =>
  request.post(`/pc-xfjg-jyjg-model/set/jyjgxz`, data).then((res) => adapter(res as any))
